package com.mdd.admin.controller.order;

import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.time.IOrderTimeService;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.validate.time.OrderTimeParam;
import com.mdd.admin.validate.time.TimeParam;
import com.mdd.admin.vo.time.OrderTimeDetailVo;
import com.mdd.admin.vo.time.OrderTimeListVo;
import com.mdd.common.constant.GlobalConstant;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.exception.OperateException;
import com.mdd.common.utils.ArrayUtil;
import com.mdd.common.utils.ConfigUtil;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 订单预约时间管理
 */
@Api(tags = "订单预约时间管理")
@RestController
@RequestMapping("api/time")
public class OrderTimeController {

    @Resource
    IOrderTimeService iOrderTimeService;

    /**
     * 订单预约时间列表
     *
     * @param pageParam 分页参数
     * @param params    搜索参数
     * @return Object
     */
    @ApiOperation(value = "订单预约时间管理 - 分页列表")
    @GetMapping("/list")
    public PageResult<OrderTimeListVo> list(@Validated PageParam pageParam,
                                            @RequestParam Map<String, String> params) {
        return iOrderTimeService.list(pageParam, params);
    }

    /**
     * 订单预约时间详情
     *
     * @param id 主键ID
     * @return Object
     */
    @ApiOperation(value = "订单预约时间管理 - 详情")
    @GetMapping("/detail")
    public OrderTimeDetailVo detail(@Validated @IDMust() @RequestParam("id") Long id) {
        return iOrderTimeService.detail(id);
    }

    /**
     * 订单预约时间新增
     *
     * @param orderTimeParam 参数
     * @return Object
     */
    @ApiOperation(value = "订单预约时间管理 - 新增")
    @Log(title = "订单预约时间新增")
    @PostMapping("/add")
    public void add(@Validated(value = OrderTimeParam.create.class) @RequestBody OrderTimeParam orderTimeParam) {
        iOrderTimeService.add(orderTimeParam);
    }

    /**
     * 订单预约时间编辑
     *
     * @param orderTimeParam 参数
     * @return Object
     */
    @ApiOperation(value = "订单预约时间管理 - 编辑")
    @Log(title = "订单预约时间编辑")
    @PostMapping("/edit")
    public void edit(@Validated(value = OrderTimeParam.update.class) @RequestBody OrderTimeParam orderTimeParam) {
        iOrderTimeService.edit(orderTimeParam);
    }

    /**
     * 订单预约时间删除
     *
     * @return Object
     */
    @ApiOperation(value = "订单预约时间管理 - 删除")
    @Log(title = "订单预约时间删除")
    @GetMapping("/del")
    public void del(@RequestParam("id") Long id) {
        iOrderTimeService.del(id);
    }

    /**
     * 订单预约时间批量删除
     *
     * @param ids 时间id集合
     */
    @ApiOperation(value = "订单预约时间管理 - 批量删除")
    @Log(title = "订单预约时间批量删除")
    @GetMapping("/batchDel")
    public void batchDel(@RequestParam Long[] ids) {
        Assert.isFalse(ids.length == 0,"时间id集合不能为空");
        iOrderTimeService.batchDel(ids);
    }

    /**
     * 获取可提前预约时间
     *
     * @return Object
     */
    @ApiOperation(value = "订单预约时间管理 - 可提前预约时长")
    @GetMapping("/getTime")
    public AjaxResult getTime() {
        return AjaxResult.success(iOrderTimeService.getOrderTime());
    }

    /**
     * 设可提前预约时间
     *
     * @return Object
     */
    @ApiOperation(value = "订单预约时间管理 - 设置提前预约时长")
    @PostMapping("/setTime")
    public void setTime(@Validated(value = TimeParam.create.class)
                            @RequestBody TimeParam timeParam) {
        iOrderTimeService.setTime(timeParam);
    }
}
